package com.test09_抽象类和接口;

import org.junit.Test;

/**
 * 接口
 */
public class YootkDemo_04 {

    @Test
    public void test1() {
        System.out.println(IBook.SITE);
        IBook book = new MathBook4();
        book.read();
        ISpec spec = new MathBook4();
        System.out.println("图书规则：" + spec.size());
        Print print = new MathBook4();
        print.batch();
    }

    @Test
    public void test2() {
        IBook book = new MathBook4();   // 向上转型
        // MathBook和ISpec接口之间有联系，所以可以互相转型
        ISpec spec = (ISpec) book;
        System.out.println(spec.size());
        Print print = (Print) spec;     // 跟上面一样，可以互相转型
        print.batch();
    }

    @Test
    public void test3() {
        IBook book = new MathBook4();
        Object obj = book;      // 通过Object接收接口引用
        IBook temp = (IBook) obj;   //向下转型
        temp.read();
    }
}

interface IPrint {
    public void batch();    //批次印刷
}

interface ISpec {
    public double size();   // 图书规则
}

interface IBook extends IPrint, ISpec {
    public static final String SITE = "www.yootk.com";  // 全局常量
    public abstract void read();    // 抽象方法
}

/**
 * 图书刊印类
 */
abstract class Print {
    public abstract void batch();   // 批量印刷
}

class MathBook4 extends Print implements IBook, ISpec {

    @Override
    public void read() {
        System.out.println("【MathBook】认真学数学");
    }

    @Override
    public double size() {
        return 7.9;
    }

    @Override
    public void batch() {
        System.out.println("【MathBook】进行数学图书的批量印刷");
    }
}
